<template>
  <div class="login">
    <el-card
      shadow="always"
      :body-style="{ padding: '20px' }"
    >
      <div slot="header">
        <span>
          亲收入用户名密码
        </span>
      </div>
      <el-form
        :model="form"
        ref="form"
        :rules="rules"
        label-width="80px"
        :inline="false"
        size="normal"
      >
        <el-form-item label="用户名">
          <el-input v-model="form.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input
            type="password"
            v-model="form.password"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            @click="login"
          >立即创建</el-button>
          <el-button @click="resetForm">取消</el-button>
        </el-form-item>
      </el-form>

    </el-card>

  </div>
</template>
<script>
// import {login} from "../api/user"
// import storage from "../utils/storage"
import { Message } from "element-ui"
export default {
  data() {
    return {
      form: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
      }
    }
  },
  methods: {
    login() {
      console.log(this.form);
      this.$refs.form.validate((valid) => {
        
        if (valid) {
          
          this.$store.dispatch("user/login", this.form).then(res => {
           Message({
             type:"success",
             message:"注册成功"
            })
            setTimeout(()=>{
              this.$router.push("/denlu")
            },1000)
          })
        }
      })
    },
    resetForm() {
      this.$refs.form.resetFields();
    }
  }
}
</script>
<style lang="scss" scoped>
.login {
  width: 25rem;
  margin: 200px auto;
}
</style>